﻿using Microsoft.AspNetCore.Mvc;
using NewRetail.Application.Components.Platform;
using NewRetail.Application.Core;
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;

namespace NewRetail.Api.Controllers
{
    [NewRetailRoute("report")]
    public class ReportController : BaseController
    {
        private readonly IReportService reportService;
        public ReportController(IReportService reportService)
        {
            this.reportService = reportService;
        }

        [HttpPost("report")]
        public async Task<ResponseEntity<PagedResultDto<ReportResponse>>> QueryReport([FromBody] ReportInput dto)
        {
            var data = await this.reportService.QueryReport(dto);
            return new ResponseEntity<PagedResultDto<ReportResponse>>().SetData(data);
        }

        [HttpPost("sales-statics-by-category")]
        public async Task<ResponseEntity<PagedResultDto<SalesStaticsByCatelogResponse>>> SalesStaticsByCatelog([FromBody] SalesStaticsByCatelogInput dto)
        {
            var res = await this.reportService.SalesStaticsByCatelog(dto);
            return new ResponseEntity<PagedResultDto<SalesStaticsByCatelogResponse>>().SetData(res);
        }

        [HttpPost("payflow-statics-by-payway")]
        public async Task<ResponseEntity<PagedResultDto<PayFlowStaticsByPayWayResponse>>> PayFlowStaticsByPayWay([FromBody] PayFlowStaticsByPayWayInput dto)
        {
            var res = await this.reportService.PayFlowStaticsByPayWay(dto);
            return new ResponseEntity<PagedResultDto<PayFlowStaticsByPayWayResponse>>().SetData(res);
        }

        [HttpPost("pay-flow-by-date")]
        public async Task<ResponseEntity<PagedResultDto<PayFlowByDateResponse>>> PayFlowByDate([FromBody] PayFlowByDateInput dto)
        {
            //var res = await this.reportService.PayFlowByDate(dto);
            //var res = await this.reportService.PayFlowByDateNew(dto);//金额小计(销售流水的销售金额)替换成付款表的付款金额
            var res = await this.reportService.PayFlowByDateBySql(dto);//金额小计(销售流水的销售金额)替换成付款表的付款金额
            return new ResponseEntity<PagedResultDto<PayFlowByDateResponse>>().SetData(res);
        }

        #region add by cl 20221113
        /// <summary>
        /// 收银员每日收银
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("sales-daily-cashier")]
        public async Task<ResponseEntity<PagedResultDto<SalesDailyCashierResponse>>> SalesDailyCashier([FromBody] SalesDailyCashierInput dto)
        {
            var res = await this.reportService.SalesDailyCashier(dto);
            return new ResponseEntity<PagedResultDto<SalesDailyCashierResponse>>().SetData(res);
        }
        /// <summary>
        /// 收银员每日收银总计。不分页
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("sales-daily-cashier-total")]
        public async Task<ResponseEntity<SalesDailyCashierTotalResponse>> SalesDailyCashierTotal([FromBody] SalesDailyCashierTotalInput dto)
        {
            var res = await this.reportService.SalesDailyCashierTotal(dto);
            return new ResponseEntity<SalesDailyCashierTotalResponse>().SetData(res);
        }
        #endregion

        #region add by cl 20230205
        /// <summary>
        /// 收银员每日收银-去掉返回值中的日期字段后的结果
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("sales-nodaily-cashier")]
        public async Task<ResponseEntity<PagedResultDto<SalesDailyCashierResponse>>> SalesNoDailyCashier([FromBody] SalesDailyCashierInput dto)
        {
            var res = await this.reportService.SalesNoDailyCashier(dto);
            return new ResponseEntity<PagedResultDto<SalesDailyCashierResponse>>().SetData(res);
        }
        /// <summary>
        /// 收银员每日收银总计。不分页
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("sales-nodaily-cashier-total")]
        public async Task<ResponseEntity<SalesDailyCashierTotalResponse>> SalesNoDailyCashierTotal([FromBody] SalesDailyCashierTotalInput dto)
        {
            var res = await this.reportService.SalesNoDailyCashierTotal(dto);
            return new ResponseEntity<SalesDailyCashierTotalResponse>().SetData(res);
        }
        #endregion

        /// <summary>
        /// 商品业务流水
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost("business-flows-reports")]
        public async Task<ResponseEntity<PagedResultDto<BusinessFlowsResponse>>> BusinessFlowsReports([FromBody] BusinessFlowsInput dto)
        {
            var res = await this.reportService.BusinessFlowsReports(dto);
            return new ResponseEntity<PagedResultDto<BusinessFlowsResponse>>().SetData(res);
        }
    }
}
